package com.tepth.vehiclemaintenance.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tepth.vehiclemaintenance.R;
import com.tepth.vehiclemaintenance.bean.MaintainListWork;
import com.tepth.vehiclemaintenance.ui.view.BadgeView;

import java.util.List;

/**
 * Created by zhangyu on 2017/5/11.
 */

public class WorkListAdapter extends BaseQuickAdapter<MaintainListWork, BaseViewHolder> {
    private Context mContext;

    public WorkListAdapter(Context context, int layoutResId, List<MaintainListWork> data) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MaintainListWork item) {
        helper.addOnClickListener(R.id.layout_bg);
        if (item.isSelected()) {
            helper.setBackgroundColor(R.id.layout_bg, mContext.getResources()
                    .getColor(R.color.white));
        } else {
            helper.setBackgroundColor(R.id.layout_bg, mContext.getResources()
                    .getColor(R.color.maintain_list_type_bg));
        }
        String personName = item.getConfirmPersonName();
        String type = item.getContentTypeName();
        if (type != null) {
            helper.setText(R.id.tv_type, item.getContentTypeName());
        }
        TextView tvPerson = helper.getView(R.id.tv_person_name);
        if (personName == null || personName.isEmpty() || "null".equals(personName)) {
            tvPerson.setVisibility(View.GONE);
        } else {
            tvPerson.setVisibility(View.VISIBLE);
            tvPerson.setText(personName);
        }
        BadgeView badgeView = helper.getView(R.id.view_badge);
        badgeView.setBadgeCount(item.getTemp_select_number());

    }
}
